/*     */ package com.newcrm.db;
/*     */ 
/*     */ import com.newcrm.businessarchives.SearchEngine;
/*     */ import com.newcrm.util.Util;
/*     */ import java.sql.Connection;
/*     */ import java.sql.SQLException;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.dbutils.DbUtils;
/*     */ import org.apache.commons.dbutils.MyMapListHandler;
/*     */ import org.apache.commons.dbutils.QueryRunner;
/*     */ import org.apache.commons.dbutils.handlers.ScalarHandler;
/*     */ import org.apache.log4j.Logger;
/*     */ 
/*     */ public class CompanyBusinessArchiveManager
/*     */ {
/*  22 */   private static Logger logger = Logger.getLogger(CompanyBusinessArchiveManager.class.getName());
/*     */ 
/*     */   public boolean isExist(String name)
/*     */   {
/*  31 */     name = SearchEngine.standardizedName(name);
/*  32 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  33 */     if (conn == null) {
/*  34 */       return false;
/*     */     }
/*  36 */     QueryRunner runner = new QueryRunner();
/*     */     try {
/*  38 */       Object obj = runner.query(conn, 
/*  39 */         "SELECT COUNT(*) FROM T_Company_BusinessArchive WHERE CompanyName = ?", new ScalarHandler(
/*  40 */         1), new Object[] { name });
/*  41 */       if (!(obj instanceof Long)) {
/*  42 */         return false;
/*     */       }
/*  44 */       int num = ((Long)obj).intValue();
/*  45 */       if (num > 0)
/*  46 */         return true;
/*     */     }
/*     */     catch (SQLException e) {
/*  49 */       logger.warn("isInstalled failed", e);
/*     */     } finally {
/*     */       try {
/*  52 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  54 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/*     */     try
/*     */     {
/*  52 */       DbUtils.close(conn);
/*     */     } catch (SQLException e) {
/*  54 */       logger.warn("close conn failed", e);
/*     */     }
/*     */ 
/*  57 */     return false;
/*     */   }
/*     */ 
/*     */   public int add(Map<String, Object> companyInfo)
/*     */   {
/*  67 */     Connection conn = ConnectionManager.getInstance().getConnection();
/*  68 */     if (conn == null) {
/*  69 */       return 0;
/*     */     }
/*     */ 
/*  72 */     if ((companyInfo == null) || (companyInfo.size() == 0)) {
/*  73 */       return 0;
/*     */     }
/*     */ 
/*  76 */     QueryRunner runner = new QueryRunner();
/*  77 */     List params = new ArrayList();
/*     */ 
/*  79 */     params.add(companyInfo.get("CompanyName"));
/*  80 */     params.add(companyInfo.get("Address"));
/*  81 */     params.add(companyInfo.get("SN"));
/*  82 */     params.add(companyInfo.get("CompanyType"));
/*  83 */     params.add(companyInfo.get("Header"));
/*  84 */     params.add(Util.str2Date(companyInfo.get("FoundedDate")));
/*  85 */     params.add(companyInfo.get("RegisteredCapital"));
/*  86 */     params.add(Integer.valueOf(Util.str2Int(companyInfo.get("OperatingPeriod"))));
/*  87 */     params.add(companyInfo.get("RegistrationAuthority"));
/*  88 */     params.add(companyInfo.get("BusinessScope"));
/*  89 */     params.add(companyInfo.get("AnnualinSpectionResult"));
/*     */     try {
/*  91 */       return runner.update(conn, "INSERT INTO T_Company_BusinessArchive(CompanyName,Address,SN,CompanyType,Header,FoundedDate,RegisteredCapital,OperatingPeriod,RegistrationAuthority,BusinessScope,AnnualinSpectionResult,CreateDate,UpdateDate) values (?,?,?,?,?,?,?,?,?,?,?,NOW(),NOW())", 
/*  92 */         params.toArray());
/*     */     } catch (SQLException e) {
/*  94 */       update(companyInfo);
/*     */     } finally {
/*     */       try {
/*  97 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/*  99 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 102 */     return 0;
/*     */   }
/*     */ 
/*     */   public int update(Map<String, Object> companyInfo)
/*     */   {
/* 112 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 113 */     if (conn == null) {
/* 114 */       return 0;
/*     */     }
/* 116 */     if ((companyInfo == null) || (companyInfo.size() == 0)) {
/* 117 */       return 0;
/*     */     }
/*     */ 
/* 120 */     QueryRunner runner = new QueryRunner();
/* 121 */     List params = new ArrayList();
/* 122 */     params.add(companyInfo.get("Address"));
/* 123 */     params.add(companyInfo.get("SN"));
/* 124 */     params.add(companyInfo.get("CompanyType"));
/* 125 */     params.add(companyInfo.get("Header"));
/* 126 */     params.add(Util.str2Date(companyInfo.get("FoundedDate")));
/* 127 */     params.add(companyInfo.get("RegisteredCapital"));
/* 128 */     params.add(Integer.valueOf(Util.str2Int(companyInfo.get("OperatingPeriod"))));
/* 129 */     params.add(companyInfo.get("RegistrationAuthority"));
/* 130 */     params.add(companyInfo.get("BusinessScope"));
/* 131 */     params.add(companyInfo.get("AnnualinSpectionResult"));
/* 132 */     params.add(companyInfo.get("CompanyName"));
/*     */     try {
/* 134 */       return runner.update(conn, 
/* 135 */         "UPDATE T_Company_BusinessArchive SET Address = ?, SN = ?, CompanyType = ?, Header = ?, FoundedDate = ?, RegisteredCapital = ?, OperatingPeriod = ?, RegistrationAuthority = ?, BusinessScope = ?, AnnualinSpectionResult = ?, UpdateDate = NOW() WHERE CompanyName = ?", params.toArray());
/*     */     } catch (SQLException e) {
/* 137 */       logger.warn("update company BusinessArchive", e);
/*     */     } finally {
/*     */       try {
/* 140 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 142 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 145 */     return 0;
/*     */   }
/*     */ 
/*     */   public Map<String, Object> getDetail(String companyName)
/*     */   {
/* 155 */     if ((companyName == null) || (companyName.trim().length() == 0)) {
/* 156 */       return null;
/*     */     }
/*     */ 
/* 159 */     Connection conn = ConnectionManager.getInstance().getConnection();
/* 160 */     if (conn == null) {
/* 161 */       return null;
/*     */     }
/* 163 */     QueryRunner runner = new QueryRunner();
/*     */     try
/*     */     {
/* 167 */       List result = (List)runner.query(conn, 
/* 168 */         "SELECT * FROM T_Company_BusinessArchive WHERE CompanyName = ?", 
/* 169 */         new MyMapListHandler(), new Object[] { companyName });
/* 170 */       if (result == null) {
/* 171 */         return null;
/*     */       }
/*     */ 
/* 174 */       if (result.size() == 0) {
/* 175 */         return null;
/*     */       }
/*     */ 
/* 178 */       return (Map)result.get(0);
/*     */     } catch (SQLException e) {
/* 180 */       logger.warn("get company BusinessArchive", e);
/*     */     } finally {
/*     */       try {
/* 183 */         DbUtils.close(conn);
/*     */       } catch (SQLException e) {
/* 185 */         logger.warn("close conn failed", e);
/*     */       }
/*     */     }
/* 188 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.db.CompanyBusinessArchiveManager
 * JD-Core Version:    0.6.1
 */